<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>编辑部门</title>
  <link rel="stylesheet" href="./static/css/common.css">
  <link rel="stylesheet" href="./static/css/layui.css" media="all">
  <style>
    .noshow {
      display: none;
    }

    .my-form-left {
      padding-left: 20px;
    }
  </style>
</head>
<body>
<div class="layui-row">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑部门</legend>
  </fieldset>
  <div class="layui-col-md6 layui-col-xs12 my-form-left">
    <form class="layui-form layui-form-pane" action="">
      <input type="hidden" id="curPageType" value="insert">
      <input type="hidden" name="id" id="id">
      <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
          <input type="text" name="departmentName" id="departmentName" lay-verify="required" autocomplete="off"
                 placeholder="请输入部门名称"
                 class="layui-input">
        </div>
      </div>
      <div class="create noshow">
        <div class="layui-form-item">
          <label class="layui-form-label">最高工资</label>
          <div class="layui-input-block">
            <input type="text" id="maxSalary" autocomplete="off" readonly class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">最低工资</label>
          <div class="layui-input-block">
            <input type="text" id="minSalary" autocomplete="off" readonly class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">平均工资</label>
          <div class="layui-input-block">
            <input type="text" id="avgSalary" autocomplete="off" readonly class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">创建时间</label>
          <div class="layui-input-block">
            <input type="text" id="createTime" autocomplete="off" readonly class="layui-input">
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="demo2">保存</button>
      </div>
    </form>
  </div>
  <div class="layui-col-md4 layui-col-xs12 create">
    <div class="layui-carousel" id="test1" lay-filter="test1" style="width: 100%;">
      <div carousel-item="" style="width: 100%;">
        <div style="width: 100%;">
          <img src="./static/image/dep1.jpg" alt="" width="100%" height="100%">
        </div>
        <div style="width: 100%;">
          <img src="./static/image/dep2.jpg" alt="" width="100%" height="100%">
        </div>
        <div style="width: 100%;">
          <img src="./static/image/dep3.jpg" alt="" width="100%" height="100%">
        </div>
        <div style="width: 100%;">
          <img src="./static/image/dep4.jpg" alt="" width="100%" height="100%">
        </div>
        <div style="width: 100%;">
          <img src="./static/image/dep5.jpg" alt="" width="100%" height="100%">
        </div>
        <div style="width: 100%;">
          <img src="./static/image/dep6.jpg" alt="" width="100%" height="100%">
        </div>
      </div>
    </div>
  </div>
</div>

<script src="./static/layui.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
  layui.use(['carousel', 'form', 'layer', 'jquery'], function () {
    var carousel = layui.carousel
      , form = layui.form
      , layer = layui.layer
      , $ = layui.$;

    //监听提交
    form.on('submit(demo2)', function (data) {
      console.log(data.field);
      $.post("/StaffManagement/department/save", data.field, data => {
        if (data.code == 200) {
          swal("提示", data.message, "success").then(() => {
            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
            parent.layer.close(index); //再执行关闭
          });
        }
      })
      return false;
    });

    //常规轮播
    carousel.render({
      elem: '#test1'
      , arrow: 'hover'
    });

    $(() => {
      setTimeout(() => {
        let curPageType = $("#curPageType").val();
        console.log(curPageType);
        if (curPageType == 'update') {
          $(".create").toggleClass("noshow");
        }
      }, 300)
    })
  });
</script>

</body>
</html>